#ifndef TREEBUILDER_H
#define TREEBUILDER_H
#include "hashtree.h"
#include <stack>
#include <queue>
#include <list>

class Tree_builder
{
private:
    Hash_tree* htree;
    // rule counter

    Hash_tree* create_hash_tree();
    void induce_rules( stack<int> orgin_rule,stack<int>& result_rule );    
    stack<int> str_to_rule( string line );
    void collect_info();        // statistic M,E,profit for each rule
    void collect_info_from( string file );
    void record_retrieve( string str,queue<int>& items,float& profit );
    void update_tree( queue<int> items,float profit,Hash_node* parent );

    void prune_rules( Hash_node* p );
    void find_general( Hash_node* p );
    bool matched_rule( Hash_node* op,Hash_node* gp );
    bool side_search( Hash_node* op,Hash_node* sp,stack<int> tail );
    void cut_tail( Hash_node* p );
    
    void prune_ctree( Hash_node* parent );
	void prune_model();

    void predict(string sfile );
    void items_retrieve( string str,list<int>& items );
    bool find_match( list<int> items,Hash_node* parent );
public:
    Tree_builder();
    ~Tree_builder();
    
    void run();
};

#endif
